package com.zzh.model.factory;

/**
 * @author zhangzhihao
 * @email zhangzhihao@gongjiangren.net
 * @date 2020-11-14
 * @desc 简单工厂
 */
public class FactoryOneDemo {


    private FactoryOneDemo() {
    }

    private static class FactoryDemoHolder {
        static FactoryOneDemo factoryDemo = new FactoryOneDemo();
    }

    public static FactoryOneDemo getInstance() {
        return FactoryDemoHolder.factoryDemo;
    }


    public interface Client {
        void show();
    }

    private static class ClientOne implements Client {
        @Override
        public void show() {
            System.out.println(ClientOne.class.getSimpleName());
        }
    }

    private static class ClientTwo implements Client {
        @Override
        public void show() {
            System.out.println(ClientTwo.class.getSimpleName());
        }
    }

    public enum Constant {
        ONE,
        TWO
    }

    public static Client createClient(Constant constant) {
        switch (constant) {
            case ONE:
                return new ClientOne();
            case TWO:
                return new ClientTwo();
            default:
                return null;
        }
    }


}
